-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
req.user vs req.user #1493
base: main
Are you sure you want to change the base?
req.user vs req.user #1493
Conversation
::: tip | ||
Please note the difference between `req` in a service handler (instance of `cds.EventContext`) and `req` in an express middleware (instance of `http.IncomingMessage`). | ||
Case in point, `req.user` in a service handler is an official API and, if not explicitely set, points to `cds.context.user`. | ||
On the other hand, setting `req.user` in a custom authentication middleware is deprecated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you generally discourage the use use of req.user
in middleware or only for setting properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do recommend the usage of <cds.Request>.user
or cds.context.user
.
Our authentication middlewares only set cds.context.user
which later on is also used when constructing a cds.Request
.
<express.Request>.user
is not set by us but if custom authentication middlewares set it, it's still working but deprecated. Custom authentication middlewares should also set cds.context.user
instead.
re #1483